//** 解决问题 **//
//创建对象的变化经常由于业务需求改变而改变，如何绕过常规对象创建方法，提供一种创建对象的接口，实现松耦合
//让子类自己决定创建哪个对象，实例化哪一个类

//抽象基类
class AbsSplitter
{
public:
	virtual void split() = 0;
	virtual ~AbsSplitter(){};
};

//抽象工厂
class SplitterFactory
{
public:
	virtual AbsSplitter* CreatSplitter() = 0;
	virtual ~SplitterFactory(){}
};

//具体类 
class TxtSplitter: public Splitter
{
	virtual void split(){}
};

class PictureSplitter: public Splitter
{
	virtual void split(){}
};

class BinarySplitter: public Splitter
{
	virtual void split(){}
};

//具体类工厂
class TxtSplitterFactory: public SplitterFactory
{
public:
	virtual AbsSplitter* CreatSplitter()
	{
		return new TxtSplitter();
	}
};

class PictureSplitter: public Splitter
{
public:
	virtual AbsSplitter* CreatSplitter()
	{
		return new PictureSplitter();
	}
}

class BinarySplitter: public Splitter
{
public:
	virtual AbsSplitter* CreatSplitter()
	{
		return new BinarySplitter();
	}
}


class Mainform
{
	//依赖抽象
	SplitterFactory* factory;

public:
	MainForm(SplitterFactory* factory) //传入子类工厂对象
	{
		//形参与成员变量同名，用this区分
		this->factory = factory;
	}
	void Button_Click()
	{
		//多态的new，稳定的部分，根据传入MainForm初始化指针不同，动态的子类工厂创建对应的对象
		AbsSplitter* splitter = factory->CreatSplitter();
		splitter->split();
	}
};